1
|
|
|
import * as fs from 'fs' |
2
|
|
|
import OS from '../client/OS' |
3
|
|
|
import fastcgiParams from '../templates/fastcgiParams' |
4
|
|
|
import nginxConf from '../templates/nginx' |
5
|
|
|
import jaleNginxConf from '../templates/nginx/jale' |
6
|
|
|
import nginxMagento1Conf from '../templates/nginx/magento1' |
7
|
|
|
import nginxMagento2Conf from '../templates/nginx/magento2' |
8
|
|
|
import {ensureDirectoryExists} from '../utils/filesystem' |
9
|
|
|
import {jaleLogsPath, jaleNginxAppTemplatesPath, jaleSitesPath} from '../utils/jale' |
10
|
|
|
import Service from './service' |
11
|
|
|
|
12
|
|
|
class Nginx extends Service { |
13
|
|
|
service = 'nginx' |
14
|
|
|
requireRoot = true |
15
|
|
|
|
16
|
|
|
configPath = `${OS.getInstance().usrLocalDir}/etc/nginx/nginx.conf` |
17
|
|
|
jaleNginxFolderPath = `${OS.getInstance().usrLocalDir}/etc/nginx/jale` |
18
|
|
|
jaleNginxConfigPath = `${this.jaleNginxFolderPath}/jale.conf` |
19
|
|
|
fastCgiParamsConfigPath = `${OS.getInstance().usrLocalDir}/etc/nginx/fastcgi_params` |
20
|
|
|
|
21
|
|
|
configure = async (): Promise<boolean> => { |
22
|
|
|
await ensureDirectoryExists(this.jaleNginxFolderPath) |
23
|
|
|
await ensureDirectoryExists(`${this.jaleNginxFolderPath}/apps`) |
24
|
|
|
await ensureDirectoryExists(jaleNginxAppTemplatesPath) |
25
|
|
|
await ensureDirectoryExists(jaleSitesPath) |
26
|
|
|
await ensureDirectoryExists(`${jaleLogsPath}/nginx`) |
27
|
|
|
await this.addConfiguration() |
28
|
|
|
await this.addFallbackConfiguration() |
29
|
|
|
await this.addFastCgiParams() |
30
|
|
|
await this.addTemplates() |
31
|
|
|
|
32
|
|
|
return true |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Install the customized Nginx configuration. |
37
|
|
|
*/ |
38
|
|
|
addConfiguration = async (): Promise<void> => { |
39
|
|
|
return fs.writeFileSync(this.configPath, nginxConf) |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Install the customized Nginx configuration. |
44
|
|
|
*/ |
45
|
|
|
addFallbackConfiguration = async (): Promise<void> => { |
46
|
|
|
return fs.writeFileSync(this.jaleNginxConfigPath, jaleNginxConf) |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Install our custom fastcgi_params config for better performance. |
51
|
|
|
*/ |
52
|
|
|
addFastCgiParams = async (): Promise<void> => { |
53
|
|
|
return fs.writeFileSync(this.fastCgiParamsConfigPath, fastcgiParams) |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Install the customized Nginx app templates.. |
58
|
|
|
*/ |
59
|
|
|
addTemplates = async (): Promise<void> => { |
60
|
|
|
fs.writeFileSync(`${jaleNginxAppTemplatesPath}/magento1.conf`, nginxMagento1Conf) |
61
|
|
|
fs.writeFileSync(`${jaleNginxAppTemplatesPath}/magento2.conf`, nginxMagento2Conf) |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
export default Nginx |
67
|
|
|
|